var apiHost = wx.getStorageSync("apiHost"); //请求地址
var Appid = wx.getStorageSync('Appid');
var Secret = wx.getStorageSync('Secret');

var AppidFlag = wx.getStorageSync('AppidFlag');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    drawalsList :'',
    startFlag: 1,              //分页标识   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    var token = wx.getStorageSync('token');
    that.setData({
      token: token
    })

    that.initWithDrawals(token,0)
    that.topCountheight(); // 计算高度
  },

  /**
   * 初始化提现明细
   */
  initWithDrawals: function (token, start){
    var that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'loading',
    });

    wx.request({
      url: apiHost + "/mobile/withDrawals/withDrawals/list", //仅为示例，并非真实的接口地址
      data: {
        token: token,
        appId: AppidFlag,
        start: start,
        length :10
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var code = res.data.code;
        var msg = res.data.msg;
        if (code == "10000") {
          var drawalsData = res.data.data
          that.ordersPaging(start,drawalsData);

        } else {
          that.showMsg(msg);
        }
        wx.hideLoading();   //隐藏加载loading
      }
    })
  },

  /**
  * 下拉
  */
  scrollLower: function () {
    var that = this;

    var start = that.data.startFlag;
    var token = that.data.token;

    that.initWithDrawals(token, start);
  },

  /**
   * 商品分页
   */
  ordersPaging: function (start, drawalsData) {
    var that = this;

    if (start > 1) {
      var drawalsList = that.data.drawalsList;
      // 追加数据
      for (var i = 0; i < drawalsData.length; i++) {
        drawalsList.push(drawalsData[i])
      }
      start = parseInt(start) + 1;
    } else {
      var drawalsList = drawalsData;
      start = 2;
    }
    that.setData({
      drawalsList: drawalsList,
      startFlag: start
    })
  },


  /**
   * 计算高度
   */
  topCountheight: function () {
    var that = this;
    var query = wx.createSelectorQuery();

    var PfDetailTopCon = "";

    query.select('#PfDetailTopCon').boundingClientRect()
    query.exec(function (res) {
      PfDetailTopCon = res[0].height;
      console.log(PfDetailTopCon)
      wx.getSystemInfo({
        success: function (res) {
          that.setData({
            PfDetailBottomCon: res.windowHeight - PfDetailTopCon
          });
        }
      });
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 提示信息
   */
  showMsg: function (msg, icon) {
    wx.showToast({
      title: msg,
      icon: icon,
      duration: 2000,
      mask: true
    });
  },
})